Grabbing SPINS gradients

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.2     ✓ dplyr   1.0.7
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   1.4.0     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()

Read in the SPINS big table

spins_grads <- read_csv("../gsr_spins_concat_full")
## Warning: Missing column names filled in: 'X1' [1]
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   X1 = col_double(),
##   grad1 = col_double(),
##   grad2 = col_double(),
##   grad3 = col_double(),
##   grad4 = col_double(),
##   grad5 = col_double(),
##   grad6 = col_double(),
##   grad7 = col_double(),
##   grad8 = col_double(),
##   grad9 = col_double(),
##   grad10 = col_double(),
##   ROI = col_character(),
##   Task = col_character(),
##   Subject = col_character(),
##   Network = col_character(),
##   Site = col_character()
## )
# spins_grads <- spins_grads %>%
#   mutate(site = str_sub(`Subject`, 5, 7)) %>%
#   rename(task = `EA or RS`, 
#          subject = `Subject ID`)

read subject data

lol_spins_behav <- 
  read_csv('../data/spins_lolivers_subject_info_for_grads_2021-07-29.csv')
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   .default = col_logical(),
##   record_id = col_character(),
##   site = col_character(),
##   scanner = col_character(),
##   diagnostic_group = col_character(),
##   demo_sex = col_character(),
##   demo_age_study_entry = col_double(),
##   `fd_mean.emp_run-1_bold` = col_double(),
##   `fd_mean.emp_run-2_bold` = col_double(),
##   `fd_mean.emp_run-3_bold` = col_double(),
##   fd_mean.rest_bold = col_double(),
##   fd_max_emp = col_double(),
##   fd_mean_emp = col_double(),
##   subject = col_character()
## )
## ℹ Use `spec()` for the full column specifications.

grab some network colours

networks <- read_delim("../networks.txt", 
    "\t", escape_double = FALSE, trim_ws = TRUE) %>%
  select(NETWORK, NETWORKKEY, RED, GREEN, BLUE, ALPHA) %>%
  distinct() %>%
  add_row(NETWORK = "Subcortical", NETWORKKEY = 13, RED = 0, GREEN=0, BLUE=0, ALPHA=255) %>%
  mutate(hex = rgb(RED, GREEN, BLUE, maxColorValue = 255)) %>%
  arrange(NETWORKKEY)
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   INDEX = col_double(),
##   KEYVALUE = col_double(),
##   LABEL = col_character(),
##   RED = col_double(),
##   GREEN = col_double(),
##   BLUE = col_double(),
##   ALPHA = col_double(),
##   HEMISPHERE = col_character(),
##   NETWORK = col_character(),
##   NETWORKKEY = col_double(),
##   NETWORKSORTEDORDER = col_double(),
##   GLASSERLABELNAME = col_character()
## )
networks

fitting models

Models

So the current df is here: /projects/loliver/SPINS_PLS_Conn/data/processed/spins_behav_ea_conn_04-29-2021.csv 6:27 However, I also excluded ZHP_0110 and ZHP_0172 as they did not complete the soc cog tasks 6:27 So that df includes 356, but my current N is 354

The following participants were missing task-rest cleaned files: sub-CMP0180 sub-CMP0182 sub-CMP0191 sub-CMP0196 sub-CMP0198 sub-CMP0207 sub-CMP0213 sub-ZHH0034

The following participants were missing task-emp background files: sub-CMH0025 sub-CMH0044 sub-CMH0095 sub-CMH0138 sub-MRC0075 sub-MRP0077 sub-MRP0147 sub-MRP0149 sub-MRP0151 sub-MRP0161 sub-ZHH0038 sub-ZHP0061 sub-ZHP0086

grand_mean_grads <- spins_grads %>%
  mutate(Network = factor(Network, levels = networks$NETWORK)) %>%
  filter(Subject %in% lol_spins_behav$subject) %>%
  group_by(Site, Task, ROI, Network) %>%
  summarise_at(vars(starts_with("grad")), mean)

grand_mean_grads
grand_mean_grads %>%
  ggplot(aes(x = grad1, y = grad2, colour = Network)) +
  geom_point() +
  scale_color_manual(values = networks$hex) +
  facet_grid(Task ~ Site)

grand_mean_grads %>%
  ggplot(aes(x = grad1, y = grad3, colour = Network)) +
  geom_point() +
  scale_color_manual(values = networks$hex) +
  facet_grid(Task ~ Site)

grand_mean_grads %>%
  ggplot(aes(x = grad2, y = grad3, colour = Network)) +
  geom_point() +
  scale_color_manual(values = networks$hex) +
  facet_grid(Task ~ Site)

grand_mean_grads %>%
  ggplot(aes(x = grad1, y = grad4, colour = Network)) +
  geom_point() +
  scale_color_manual(values = networks$hex) +
  facet_grid(Task ~ Site)

From age paper: Each axis of this 3D space was defined by the values along the first three gradients. Within network dispersion was quantified as sum squared Euclidean distance of network nodes to the network centroid at individual level. Between network dispersion was calculated as the Euclidean distance between network centroids.

They also did linear models on nodal values from the first three gradients

calculating centroid and within network dispersion

## calculate the network centers
subject_level_centers <- spins_grads %>%
  filter(Subject %in% lol_spins_behav$subject) %>%
  group_by(Site, Task, Network, Subject) %>%
  summarise_at(c("grad1", "grad2", "grad3"), mean)
  
subject_within_dispersion <- subject_level_centers %>%
  
  ## combine with orig spins grads
  inner_join(spins_grads, by = c("Site", "Task", "Network", "Subject"), suffix = c("_center", "")) %>%
  
  ## calculate squared euclidian distance from the network centroid  
  ungroup() %>%
  mutate(roi_distance_sq = (grad1_center - grad1)**2 + (grad2_center - grad2)**2 + (grad3_center - grad3)**2) %>% 
  
  ## dispersion as the sum of the squared distances within network and participant
  group_by(Site, Task, Network, Subject) %>%
  summarise(within_dispersion = sum(roi_distance_sq))
## `summarise()` has grouped output by 'Site', 'Task', 'Network'. You can override using the `.groups` argument.

calculating between network dispersion

Between network dispersion was calculated as the Euclidean distance between network centroids.

library(igraph)
## 
## Attaching package: 'igraph'
## The following objects are masked from 'package:dplyr':
## 
##     as_data_frame, groups, union
## The following objects are masked from 'package:purrr':
## 
##     compose, simplify
## The following object is masked from 'package:tidyr':
## 
##     crossing
## The following object is masked from 'package:tibble':
## 
##     as_data_frame
## The following objects are masked from 'package:stats':
## 
##     decompose, spectrum
## The following object is masked from 'package:base':
## 
##     union
## assumes that the network_centroids contains columns "Network", "grad1", "grad2", "grad3"
calc_between_distances <- function(network_centoids) {
  ## grab the unique network node names
  network_names <- unique(network_centoids$Network)

  ## create a graph dataframe of edges
  result <- make_full_graph(length(network_names), directed = FALSE) %>% as_data_frame()
  
  for (i in 1:nrow(result)) {
    to_name <- network_names[result$to[i]]
    from_name <- network_names[result$from[i]]
   
    result$to_name[i] <- to_name
    result$from_name[i] <- from_name

  res_df <- test_centroids %>%
    filter(Network == to_name | Network == from_name) %>%
    mutate_at(vars(c("grad1", "grad2", "grad3")), function(x) {(x - lag(x))**2}) %>%
    mutate(eucl_dist = sqrt(grad1 + grad2 + grad3))

  result$eucl_dist[i] <- res_df$eucl_dist[2]

  }

  return(result %>% select(to_name, from_name, eucl_dist))
}
between_network <- subject_level_centers %>%
  ungroup() %>%
  group_by(Site, Task, Subject) %>%
  nest() %>%
  mutate(distances = map(data, calc_between_distances)) 
library(broom)
subject_level_centers %>%
  inner_join(lol_spins_behav, by = c("Subject" = "subject")) %>%
  mutate( fd_mean = if_else(Task=="EA", fd_mean_emp, `fd_mean.rest_bold`)) %>%
  ungroup() %>%
  group_by(Network) %>%
  do(tidy(aov(grad1 ~ Task + fd_mean_emp + scanner + Error(Subject), data = .))) %>%
  knitr::kable()
Network stratum term df sumsq meansq statistic p.value
Auditory Subject fd_mean_emp 1 0.3641676 0.3641676 22.0720637 0.0000038
Auditory Subject scanner 5 0.8568149 0.1713630 10.3862459 0.0000000
Auditory Subject Residuals 340 5.6096700 0.0164990 NA NA
Auditory Within Task 1 2.1693074 2.1693074 172.0018255 0.0000000
Auditory Within Residuals 346 4.3637929 0.0126121 NA NA
Cingulo-Opercular Subject fd_mean_emp 1 0.3349874 0.3349874 44.4056434 0.0000000
Cingulo-Opercular Subject scanner 5 0.2603116 0.0520623 6.9013348 0.0000037
Cingulo-Opercular Subject Residuals 340 2.5648932 0.0075438 NA NA
Cingulo-Opercular Within Task 1 0.4599271 0.4599271 82.8383865 0.0000000
Cingulo-Opercular Within Residuals 346 1.9210269 0.0055521 NA NA
Default Subject fd_mean_emp 1 0.4716523 0.4716523 40.7667179 0.0000000
Default Subject scanner 5 0.2417948 0.0483590 4.1798504 0.0010644
Default Subject Residuals 340 3.9336449 0.0115695 NA NA
Default Within Task 1 2.3251745 2.3251745 300.0467949 0.0000000
Default Within Residuals 346 2.6812830 0.0077494 NA NA
Dorsal-Attention Subject fd_mean_emp 1 0.0214715 0.0214715 2.9369777 0.0874840
Dorsal-Attention Subject scanner 5 0.1322006 0.0264401 3.6166032 0.0033528
Dorsal-Attention Subject Residuals 340 2.4856594 0.0073108 NA NA
Dorsal-Attention Within Task 1 0.0514999 0.0514999 9.1518003 0.0026706
Dorsal-Attention Within Residuals 346 1.9470454 0.0056273 NA NA
Frontoparietal Subject fd_mean_emp 1 0.3005887 0.3005887 31.9516804 0.0000000
Frontoparietal Subject scanner 5 0.3664047 0.0732809 7.7895454 0.0000006
Frontoparietal Subject Residuals 340 3.1985847 0.0094076 NA NA
Frontoparietal Within Task 1 1.7578251 1.7578251 266.3016782 0.0000000
Frontoparietal Within Residuals 346 2.2839041 0.0066009 NA NA
Language Subject fd_mean_emp 1 0.1480215 0.1480215 10.6038041 0.0012422
Language Subject scanner 5 0.2588106 0.0517621 3.7080795 0.0027858
Language Subject Residuals 340 4.7461547 0.0139593 NA NA
Language Within Task 1 0.1373327 0.1373327 13.1559501 0.0003297
Language Within Residuals 346 3.6118352 0.0104388 NA NA
Orbito-Affective Subject fd_mean_emp 1 0.0011489 0.0011489 0.0767487 0.7819212
Orbito-Affective Subject scanner 5 0.0747757 0.0149551 0.9990240 0.4182529
Orbito-Affective Subject Residuals 340 5.0897161 0.0149698 NA NA
Orbito-Affective Within Task 1 0.2858827 0.2858827 26.0053259 0.0000006
Orbito-Affective Within Residuals 346 3.8036601 0.0109932 NA NA
Posterior-Multimodal Subject fd_mean_emp 1 0.0000198 0.0000198 0.0007252 0.9785324
Posterior-Multimodal Subject scanner 5 0.0842328 0.0168466 0.6183091 0.6859403
Posterior-Multimodal Subject Residuals 340 9.2636979 0.0272462 NA NA
Posterior-Multimodal Within Task 1 0.3942566 0.3942566 31.0817744 0.0000000
Posterior-Multimodal Within Residuals 346 4.3888353 0.0126845 NA NA
Somatomotor Subject fd_mean_emp 1 0.4423978 0.4423978 34.5354962 0.0000000
Somatomotor Subject scanner 5 0.2050523 0.0410105 3.2014540 0.0077211
Somatomotor Subject Residuals 340 4.3553814 0.0128099 NA NA
Somatomotor Within Task 1 2.0056268 2.0056268 220.4347105 0.0000000
Somatomotor Within Residuals 346 3.1480836 0.0090985 NA NA
Subcortical Subject fd_mean_emp 1 0.0731462 0.0731462 10.2574148 0.0014900
Subcortical Subject scanner 5 0.0182739 0.0036548 0.5125148 0.7667966
Subcortical Subject Residuals 340 2.4245596 0.0071311 NA NA
Subcortical Within Task 1 0.0374143 0.0374143 6.1877745 0.0133340
Subcortical Within Residuals 346 2.0920866 0.0060465 NA NA
Ventral-Multimodal Subject fd_mean_emp 1 0.0000435 0.0000435 0.0021813 0.9627762
Ventral-Multimodal Subject scanner 5 0.1395341 0.0279068 1.4009119 0.2233415
Ventral-Multimodal Subject Residuals 340 6.7729600 0.0199205 NA NA
Ventral-Multimodal Within Task 1 0.2317625 0.2317625 11.3864411 0.0008237
Ventral-Multimodal Within Residuals 346 7.0425719 0.0203543 NA NA
Visual1 Subject fd_mean_emp 1 0.0894716 0.0894716 3.7360894 0.0540791
Visual1 Subject scanner 5 0.2763372 0.0552674 2.3078180 0.0440452
Visual1 Subject Residuals 340 8.1422931 0.0239479 NA NA
Visual1 Within Task 1 0.0392833 0.0392833 1.8594923 0.1735699
Visual1 Within Residuals 346 7.3095276 0.0211258 NA NA
Visual2 Subject fd_mean_emp 1 0.1624415 0.1624415 19.6307351 0.0000127
Visual2 Subject scanner 5 0.2908200 0.0581640 7.0290036 0.0000029
Visual2 Subject Residuals 340 2.8134516 0.0082749 NA NA
Visual2 Within Task 1 1.5586961 1.5586961 198.8719691 0.0000000
Visual2 Within Residuals 346 2.7118394 0.0078377 NA NA
results_subject_within_dispersion <- subject_within_dispersion %>%
  inner_join(lol_spins_behav, by = c("Subject" = "subject")) %>%
  mutate( fd_mean = if_else(Task=="EA", fd_mean_emp, `fd_mean.rest_bold`)) %>%
  group_by(Network, Task) %>%
  do(tidy(lm(within_dispersion ~ diagnostic_group + demo_age_study_entry + demo_sex + fd_mean + scanner, data = .))) %>%
  ungroup() %>%
  group_by(term) %>%
  mutate(p_FDR = p.adjust(p.value, method = "fdr"))

results_subject_within_dispersion %>%
  filter(term == "diagnostic_groupcontrol") %>%
  knitr::kable()
Network Task term estimate std.error statistic p.value p_FDR
Auditory EA diagnostic_groupcontrol -0.0221795 0.0309387 -0.7168855 0.4739413 0.6888323
Auditory RS diagnostic_groupcontrol 0.0999724 0.0683704 1.4622176 0.1446135 0.4699938
Cingulo-Opercular EA diagnostic_groupcontrol 0.0992081 0.2140203 0.4635454 0.6432727 0.8362545
Cingulo-Opercular RS diagnostic_groupcontrol 0.3931632 0.3239122 1.2137957 0.2256757 0.5192920
Default EA diagnostic_groupcontrol -0.6929686 0.2628557 -2.6363079 0.0087692 0.0901199
Default RS diagnostic_groupcontrol 0.3864732 0.4827888 0.8005017 0.4239841 0.6888323
Dorsal-Attention EA diagnostic_groupcontrol -0.0428020 0.1156782 -0.3700094 0.7116079 0.8409912
Dorsal-Attention RS diagnostic_groupcontrol 0.4549504 0.1708437 2.6629621 0.0081173 0.0901199
Frontoparietal EA diagnostic_groupcontrol -0.5036294 0.1969466 -2.5571875 0.0109897 0.0901199
Frontoparietal RS diagnostic_groupcontrol -0.7514029 0.3037572 -2.4736959 0.0138646 0.0901199
Language EA diagnostic_groupcontrol -0.2127577 0.0990738 -2.1474678 0.0324689 0.1406986
Language RS diagnostic_groupcontrol -0.1733343 0.1713951 -1.0113139 0.3125918 0.5805276
Orbito-Affective EA diagnostic_groupcontrol -0.0045974 0.0121072 -0.3797240 0.7043895 0.8409912
Orbito-Affective RS diagnostic_groupcontrol -0.0415057 0.0353485 -1.1741840 0.2411504 0.5192920
Posterior-Multimodal EA diagnostic_groupcontrol -0.0249051 0.0349732 -0.7121189 0.4768839 0.6888323
Posterior-Multimodal RS diagnostic_groupcontrol 0.0035891 0.0666705 0.0538337 0.9570996 0.9570996
Somatomotor EA diagnostic_groupcontrol -0.0488648 0.1041735 -0.4690711 0.6393221 0.8362545
Somatomotor RS diagnostic_groupcontrol 0.4158732 0.2185773 1.9026363 0.0579402 0.2152063
Subcortical EA diagnostic_groupcontrol 0.1069146 0.0946875 1.1291303 0.2596460 0.5192920
Subcortical RS diagnostic_groupcontrol 0.4563074 0.1929949 2.3643499 0.0186282 0.0968668
Ventral-Multimodal EA diagnostic_groupcontrol -0.0006241 0.0051602 -0.1209375 0.9038126 0.9570996
Ventral-Multimodal RS diagnostic_groupcontrol -0.0316949 0.0235153 -1.3478422 0.1786145 0.5159974
Visual1 EA diagnostic_groupcontrol -0.0015026 0.0268451 -0.0559744 0.9553954 0.9570996
Visual1 RS diagnostic_groupcontrol -0.0680618 0.0551739 -1.2335871 0.2182165 0.5192920
Visual2 EA diagnostic_groupcontrol 0.0569670 0.1760929 0.3235053 0.7465132 0.8438845
Visual2 RS diagnostic_groupcontrol 0.2712569 0.3767612 0.7199704 0.4720422 0.6888323
results_subject_within_dispersion %>%
  filter(term == "demo_age_study_entry") %>%
  knitr::kable()
Network Task term estimate std.error statistic p.value p_FDR
Auditory EA demo_age_study_entry -0.0000988 0.0016345 -0.0604371 0.9518433 0.9518433
Auditory RS demo_age_study_entry 0.0005796 0.0037155 0.1559859 0.8761375 0.9491490
Cingulo-Opercular EA demo_age_study_entry -0.0472094 0.0113071 -4.1752069 0.0000379 0.0004933
Cingulo-Opercular RS demo_age_study_entry -0.0126022 0.0176027 -0.7159244 0.4745338 0.8225253
Default EA demo_age_study_entry -0.0416489 0.0138871 -2.9991011 0.0029092 0.0189100
Default RS demo_age_study_entry -0.0092580 0.0262367 -0.3528639 0.7244111 0.8968899
Dorsal-Attention EA demo_age_study_entry -0.0193355 0.0061115 -3.1637989 0.0016990 0.0147247
Dorsal-Attention RS demo_age_study_entry 0.0120384 0.0092843 1.2966338 0.1956444 0.4235606
Frontoparietal EA demo_age_study_entry -0.0449890 0.0104050 -4.3237692 0.0000202 0.0004933
Frontoparietal RS demo_age_study_entry -0.0214694 0.0165074 -1.3005949 0.1942858 0.4235606
Language EA demo_age_study_entry -0.0065484 0.0052342 -1.2510602 0.2117803 0.4235606
Language RS demo_age_study_entry -0.0044197 0.0093143 -0.4745060 0.6354465 0.8968899
Orbito-Affective EA demo_age_study_entry -0.0008387 0.0006396 -1.3111766 0.1906908 0.4235606
Orbito-Affective RS demo_age_study_entry 0.0030955 0.0019210 1.6114026 0.1080281 0.3510914
Posterior-Multimodal EA demo_age_study_entry -0.0044179 0.0018477 -2.3910073 0.0173505 0.0902224
Posterior-Multimodal RS demo_age_study_entry 0.0015324 0.0036231 0.4229378 0.6726104 0.8968899
Somatomotor EA demo_age_study_entry 0.0102813 0.0055037 1.8680730 0.0626195 0.2325868
Somatomotor RS demo_age_study_entry 0.0021319 0.0118784 0.1794818 0.8576673 0.9491490
Subcortical EA demo_age_study_entry -0.0115726 0.0050025 -2.3133664 0.0213040 0.0923172
Subcortical RS demo_age_study_entry -0.0142556 0.0104881 -1.3592121 0.1749883 0.4235606
Ventral-Multimodal EA demo_age_study_entry -0.0002191 0.0002726 -0.8038591 0.4220450 0.7837979
Ventral-Multimodal RS demo_age_study_entry 0.0005797 0.0012779 0.4536643 0.6503625 0.8968899
Visual1 EA demo_age_study_entry -0.0001441 0.0014183 -0.1016220 0.9191172 0.9518433
Visual1 RS demo_age_study_entry -0.0008586 0.0029984 -0.2863701 0.7747706 0.9156380
Visual2 EA demo_age_study_entry -0.0044399 0.0093033 -0.4772387 0.6335015 0.8968899
Visual2 RS demo_age_study_entry 0.0076648 0.0204747 0.3743528 0.7083773 0.8968899
net_centroids_results <- subject_level_centers %>%
  inner_join(lol_spins_behav, by = c("Subject" = "subject")) %>%
  mutate( fd_mean = if_else(Task=="EA", fd_mean_emp, `fd_mean.rest_bold`)) %>%

  pivot_longer(starts_with("grad"), names_to = "grad_num", values_to = "grad_value") %>%
    ungroup() %>%
  group_by(Network, Task, grad_num) %>%
  do(tidy(lm(grad_value ~ diagnostic_group + demo_age_study_entry + demo_sex + fd_mean + scanner, data = .))) %>%
  ungroup() %>%
  group_by(term) %>%
  mutate(p_FDR = p.adjust(p.value, method = "fdr"))

net_centroids_results %>%
  filter(term == "diagnostic_groupcontrol") %>%
  arrange(grad_num, Task) %>%
  knitr::kable()
Network Task grad_num term estimate std.error statistic p.value p_FDR
Auditory EA grad1 diagnostic_groupcontrol 0.0239680 0.0092808 2.5825409 0.0102288 0.0379928
Cingulo-Opercular EA grad1 diagnostic_groupcontrol 0.0146874 0.0068312 2.1500320 0.0322639 0.1006633
Default EA grad1 diagnostic_groupcontrol -0.0376677 0.0078740 -4.7838048 0.0000026 0.0001005
Dorsal-Attention EA grad1 diagnostic_groupcontrol 0.0065356 0.0061926 1.0553855 0.2920051 0.5066699
Frontoparietal EA grad1 diagnostic_groupcontrol -0.0083782 0.0065259 -1.2838482 0.2000771 0.3901503
Language EA grad1 diagnostic_groupcontrol 0.0145716 0.0079548 1.8317936 0.0678647 0.1764481
Orbito-Affective EA grad1 diagnostic_groupcontrol 0.0004807 0.0087882 0.0547014 0.9564087 0.9564087
Posterior-Multimodal EA grad1 diagnostic_groupcontrol -0.0064001 0.0108629 -0.5891675 0.5561436 0.6730968
Somatomotor EA grad1 diagnostic_groupcontrol 0.0162528 0.0089713 1.8116381 0.0709322 0.1784746
Subcortical EA grad1 diagnostic_groupcontrol -0.0014148 0.0052628 -0.2688300 0.7882250 0.8513553
Ventral-Multimodal EA grad1 diagnostic_groupcontrol -0.0095459 0.0100210 -0.9525960 0.3414775 0.5790271
Visual1 EA grad1 diagnostic_groupcontrol 0.0068381 0.0091587 0.7466176 0.4558150 0.6348852
Visual2 EA grad1 diagnostic_groupcontrol 0.0168989 0.0061751 2.7366396 0.0065361 0.0299890
Auditory RS grad1 diagnostic_groupcontrol 0.0336612 0.0161283 2.0870909 0.0376309 0.1128928
Cingulo-Opercular RS grad1 diagnostic_groupcontrol 0.0357243 0.0097576 3.6611913 0.0002914 0.0036180
Default RS grad1 diagnostic_groupcontrol -0.0345143 0.0122000 -2.8290313 0.0049485 0.0257323
Dorsal-Attention RS grad1 diagnostic_groupcontrol -0.0016279 0.0107539 -0.1513808 0.8797659 0.9029177
Frontoparietal RS grad1 diagnostic_groupcontrol 0.0048787 0.0121007 0.4031766 0.6870740 0.7774983
Language RS grad1 diagnostic_groupcontrol 0.0088708 0.0152402 0.5820622 0.5609140 0.6730968
Orbito-Affective RS grad1 diagnostic_groupcontrol -0.0069285 0.0155307 -0.4461156 0.6558002 0.7634689
Posterior-Multimodal RS grad1 diagnostic_groupcontrol -0.0249197 0.0193463 -1.2880865 0.1985996 0.3901503
Somatomotor RS grad1 diagnostic_groupcontrol -0.0123419 0.0134545 -0.9173031 0.3596398 0.5844480
Subcortical RS grad1 diagnostic_groupcontrol 0.0182000 0.0114169 1.5941232 0.1118458 0.2492565
Ventral-Multimodal RS grad1 diagnostic_groupcontrol 0.0334800 0.0197041 1.6991425 0.0902152 0.2132359
Visual1 RS grad1 diagnostic_groupcontrol -0.0594700 0.0214347 -2.7744708 0.0058374 0.0284573
Visual2 RS grad1 diagnostic_groupcontrol -0.0242399 0.0124447 -1.9478128 0.0522674 0.1456021
Auditory EA grad2 diagnostic_groupcontrol -0.0132153 0.0096221 -1.3734335 0.1705306 0.3500366
Cingulo-Opercular EA grad2 diagnostic_groupcontrol 0.0046755 0.0050972 0.9172640 0.3596603 0.5844480
Default EA grad2 diagnostic_groupcontrol 0.0002702 0.0036744 0.0735465 0.9414148 0.9536410
Dorsal-Attention EA grad2 diagnostic_groupcontrol -0.0038127 0.0065339 -0.5835214 0.5599327 0.6730968
Frontoparietal EA grad2 diagnostic_groupcontrol 0.0010002 0.0044215 0.2262056 0.8211787 0.8655667
Language EA grad2 diagnostic_groupcontrol -0.0133176 0.0061530 -2.1643975 0.0311357 0.1006633
Orbito-Affective EA grad2 diagnostic_groupcontrol 0.0218019 0.0074438 2.9288783 0.0036335 0.0202441
Posterior-Multimodal EA grad2 diagnostic_groupcontrol -0.0085209 0.0097965 -0.8697876 0.3850356 0.6006555
Somatomotor EA grad2 diagnostic_groupcontrol -0.0014679 0.0078331 -0.1873912 0.8514667 0.8855253
Subcortical EA grad2 diagnostic_groupcontrol -0.0019997 0.0061273 -0.3263526 0.7443602 0.8177478
Ventral-Multimodal EA grad2 diagnostic_groupcontrol -0.0066462 0.0093836 -0.7082754 0.4792639 0.6511018
Visual1 EA grad2 diagnostic_groupcontrol 0.0096343 0.0121732 0.7914346 0.4292471 0.6193960
Visual2 EA grad2 diagnostic_groupcontrol 0.0058452 0.0087851 0.6653587 0.5062762 0.6630601
Auditory RS grad2 diagnostic_groupcontrol -0.0613518 0.0163841 -3.7445960 0.0002124 0.0033139
Cingulo-Opercular RS grad2 diagnostic_groupcontrol -0.0419363 0.0095306 -4.4001802 0.0000145 0.0003778
Default RS grad2 diagnostic_groupcontrol -0.0074203 0.0065580 -1.1314897 0.2586535 0.4697058
Dorsal-Attention RS grad2 diagnostic_groupcontrol 0.0414994 0.0132380 3.1348567 0.0018705 0.0112232
Frontoparietal RS grad2 diagnostic_groupcontrol -0.0179810 0.0074568 -2.4113765 0.0164268 0.0582404
Language RS grad2 diagnostic_groupcontrol 0.0092382 0.0111450 0.8289069 0.4077438 0.6116157
Orbito-Affective RS grad2 diagnostic_groupcontrol -0.0110916 0.0136109 -0.8149061 0.4157016 0.6117872
Posterior-Multimodal RS grad2 diagnostic_groupcontrol 0.0198206 0.0172853 1.1466741 0.2523298 0.4697058
Somatomotor RS grad2 diagnostic_groupcontrol -0.0381138 0.0142219 -2.6799330 0.0077253 0.0334765
Subcortical RS grad2 diagnostic_groupcontrol -0.0282857 0.0087827 -3.2206173 0.0014038 0.0091245
Ventral-Multimodal RS grad2 diagnostic_groupcontrol 0.0073589 0.0182964 0.4022066 0.6877870 0.7774983
Visual1 RS grad2 diagnostic_groupcontrol 0.0179466 0.0256228 0.7004131 0.4841526 0.6511018
Visual2 RS grad2 diagnostic_groupcontrol 0.1144097 0.0157738 7.2531338 0.0000000 0.0000000
Auditory EA grad3 diagnostic_groupcontrol -0.0156858 0.0110482 -1.4197603 0.1566019 0.3393040
Cingulo-Opercular EA grad3 diagnostic_groupcontrol 0.0044706 0.0049661 0.9002179 0.3686472 0.5868261
Default EA grad3 diagnostic_groupcontrol 0.0034915 0.0054026 0.6462660 0.5185470 0.6630601
Dorsal-Attention EA grad3 diagnostic_groupcontrol 0.0017452 0.0067718 0.2577188 0.7967813 0.8513553
Frontoparietal EA grad3 diagnostic_groupcontrol 0.0031561 0.0061960 0.5093809 0.6108187 0.7218766
Language EA grad3 diagnostic_groupcontrol 0.0031840 0.0088005 0.3618029 0.7177260 0.7997519
Orbito-Affective EA grad3 diagnostic_groupcontrol -0.0057439 0.0088543 -0.6487161 0.5169637 0.6630601
Posterior-Multimodal EA grad3 diagnostic_groupcontrol 0.0299112 0.0114921 2.6027559 0.0096563 0.0376597
Somatomotor EA grad3 diagnostic_groupcontrol -0.0209442 0.0063079 -3.3203199 0.0009976 0.0077814
Subcortical EA grad3 diagnostic_groupcontrol 0.0226621 0.0062437 3.6296057 0.0003279 0.0036180
Ventral-Multimodal EA grad3 diagnostic_groupcontrol -0.0112839 0.0106985 -1.0547187 0.2923096 0.5066699
Visual1 EA grad3 diagnostic_groupcontrol -0.0142646 0.0085054 -1.6771183 0.0944466 0.2166716
Visual2 EA grad3 diagnostic_groupcontrol -0.0053467 0.0038924 -1.3736174 0.1704736 0.3500366
Auditory RS grad3 diagnostic_groupcontrol 0.0121786 0.0156414 0.7786139 0.4367536 0.6193960
Cingulo-Opercular RS grad3 diagnostic_groupcontrol 0.0067627 0.0080353 0.8416301 0.4005919 0.6116157
Default RS grad3 diagnostic_groupcontrol 0.0235588 0.0071710 3.2852716 0.0011260 0.0079840
Dorsal-Attention RS grad3 diagnostic_groupcontrol -0.0253400 0.0110227 -2.2989032 0.0221218 0.0750218
Frontoparietal RS grad3 diagnostic_groupcontrol 0.0051760 0.0085082 0.6083469 0.5433672 0.6730968
Language RS grad3 diagnostic_groupcontrol -0.0239176 0.0120263 -1.9887681 0.0475352 0.1373238
Orbito-Affective RS grad3 diagnostic_groupcontrol 0.0402752 0.0152691 2.6376983 0.0087341 0.0358556
Posterior-Multimodal RS grad3 diagnostic_groupcontrol -0.0206704 0.0182793 -1.1308072 0.2589404 0.4697058
Somatomotor RS grad3 diagnostic_groupcontrol -0.0180773 0.0103476 -1.7469985 0.0815486 0.1987746
Subcortical RS grad3 diagnostic_groupcontrol 0.0410243 0.0101849 4.0279734 0.0000696 0.0013565
Ventral-Multimodal RS grad3 diagnostic_groupcontrol -0.0345523 0.0179343 -1.9266061 0.0548694 0.1475797
Visual1 RS grad3 diagnostic_groupcontrol -0.0571140 0.0167060 -3.4187666 0.0007062 0.0061204
Visual2 RS grad3 diagnostic_groupcontrol -0.0299806 0.0083366 -3.5962783 0.0003711 0.0036180
net_centroids_results %>%
  filter(term == "diagnostic_groupcontrol") %>%
  arrange(grad_num, Task) %>%
  knitr::kable()
Network Task grad_num term estimate std.error statistic p.value p_FDR
Auditory EA grad1 diagnostic_groupcontrol 0.0239680 0.0092808 2.5825409 0.0102288 0.0379928
Cingulo-Opercular EA grad1 diagnostic_groupcontrol 0.0146874 0.0068312 2.1500320 0.0322639 0.1006633
Default EA grad1 diagnostic_groupcontrol -0.0376677 0.0078740 -4.7838048 0.0000026 0.0001005
Dorsal-Attention EA grad1 diagnostic_groupcontrol 0.0065356 0.0061926 1.0553855 0.2920051 0.5066699
Frontoparietal EA grad1 diagnostic_groupcontrol -0.0083782 0.0065259 -1.2838482 0.2000771 0.3901503
Language EA grad1 diagnostic_groupcontrol 0.0145716 0.0079548 1.8317936 0.0678647 0.1764481
Orbito-Affective EA grad1 diagnostic_groupcontrol 0.0004807 0.0087882 0.0547014 0.9564087 0.9564087
Posterior-Multimodal EA grad1 diagnostic_groupcontrol -0.0064001 0.0108629 -0.5891675 0.5561436 0.6730968
Somatomotor EA grad1 diagnostic_groupcontrol 0.0162528 0.0089713 1.8116381 0.0709322 0.1784746
Subcortical EA grad1 diagnostic_groupcontrol -0.0014148 0.0052628 -0.2688300 0.7882250 0.8513553
Ventral-Multimodal EA grad1 diagnostic_groupcontrol -0.0095459 0.0100210 -0.9525960 0.3414775 0.5790271
Visual1 EA grad1 diagnostic_groupcontrol 0.0068381 0.0091587 0.7466176 0.4558150 0.6348852
Visual2 EA grad1 diagnostic_groupcontrol 0.0168989 0.0061751 2.7366396 0.0065361 0.0299890
Auditory RS grad1 diagnostic_groupcontrol 0.0336612 0.0161283 2.0870909 0.0376309 0.1128928
Cingulo-Opercular RS grad1 diagnostic_groupcontrol 0.0357243 0.0097576 3.6611913 0.0002914 0.0036180
Default RS grad1 diagnostic_groupcontrol -0.0345143 0.0122000 -2.8290313 0.0049485 0.0257323
Dorsal-Attention RS grad1 diagnostic_groupcontrol -0.0016279 0.0107539 -0.1513808 0.8797659 0.9029177
Frontoparietal RS grad1 diagnostic_groupcontrol 0.0048787 0.0121007 0.4031766 0.6870740 0.7774983
Language RS grad1 diagnostic_groupcontrol 0.0088708 0.0152402 0.5820622 0.5609140 0.6730968
Orbito-Affective RS grad1 diagnostic_groupcontrol -0.0069285 0.0155307 -0.4461156 0.6558002 0.7634689
Posterior-Multimodal RS grad1 diagnostic_groupcontrol -0.0249197 0.0193463 -1.2880865 0.1985996 0.3901503
Somatomotor RS grad1 diagnostic_groupcontrol -0.0123419 0.0134545 -0.9173031 0.3596398 0.5844480
Subcortical RS grad1 diagnostic_groupcontrol 0.0182000 0.0114169 1.5941232 0.1118458 0.2492565
Ventral-Multimodal RS grad1 diagnostic_groupcontrol 0.0334800 0.0197041 1.6991425 0.0902152 0.2132359
Visual1 RS grad1 diagnostic_groupcontrol -0.0594700 0.0214347 -2.7744708 0.0058374 0.0284573
Visual2 RS grad1 diagnostic_groupcontrol -0.0242399 0.0124447 -1.9478128 0.0522674 0.1456021
Auditory EA grad2 diagnostic_groupcontrol -0.0132153 0.0096221 -1.3734335 0.1705306 0.3500366
Cingulo-Opercular EA grad2 diagnostic_groupcontrol 0.0046755 0.0050972 0.9172640 0.3596603 0.5844480
Default EA grad2 diagnostic_groupcontrol 0.0002702 0.0036744 0.0735465 0.9414148 0.9536410
Dorsal-Attention EA grad2 diagnostic_groupcontrol -0.0038127 0.0065339 -0.5835214 0.5599327 0.6730968
Frontoparietal EA grad2 diagnostic_groupcontrol 0.0010002 0.0044215 0.2262056 0.8211787 0.8655667
Language EA grad2 diagnostic_groupcontrol -0.0133176 0.0061530 -2.1643975 0.0311357 0.1006633
Orbito-Affective EA grad2 diagnostic_groupcontrol 0.0218019 0.0074438 2.9288783 0.0036335 0.0202441
Posterior-Multimodal EA grad2 diagnostic_groupcontrol -0.0085209 0.0097965 -0.8697876 0.3850356 0.6006555
Somatomotor EA grad2 diagnostic_groupcontrol -0.0014679 0.0078331 -0.1873912 0.8514667 0.8855253
Subcortical EA grad2 diagnostic_groupcontrol -0.0019997 0.0061273 -0.3263526 0.7443602 0.8177478
Ventral-Multimodal EA grad2 diagnostic_groupcontrol -0.0066462 0.0093836 -0.7082754 0.4792639 0.6511018
Visual1 EA grad2 diagnostic_groupcontrol 0.0096343 0.0121732 0.7914346 0.4292471 0.6193960
Visual2 EA grad2 diagnostic_groupcontrol 0.0058452 0.0087851 0.6653587 0.5062762 0.6630601
Auditory RS grad2 diagnostic_groupcontrol -0.0613518 0.0163841 -3.7445960 0.0002124 0.0033139
Cingulo-Opercular RS grad2 diagnostic_groupcontrol -0.0419363 0.0095306 -4.4001802 0.0000145 0.0003778
Default RS grad2 diagnostic_groupcontrol -0.0074203 0.0065580 -1.1314897 0.2586535 0.4697058
Dorsal-Attention RS grad2 diagnostic_groupcontrol 0.0414994 0.0132380 3.1348567 0.0018705 0.0112232
Frontoparietal RS grad2 diagnostic_groupcontrol -0.0179810 0.0074568 -2.4113765 0.0164268 0.0582404
Language RS grad2 diagnostic_groupcontrol 0.0092382 0.0111450 0.8289069 0.4077438 0.6116157
Orbito-Affective RS grad2 diagnostic_groupcontrol -0.0110916 0.0136109 -0.8149061 0.4157016 0.6117872
Posterior-Multimodal RS grad2 diagnostic_groupcontrol 0.0198206 0.0172853 1.1466741 0.2523298 0.4697058
Somatomotor RS grad2 diagnostic_groupcontrol -0.0381138 0.0142219 -2.6799330 0.0077253 0.0334765
Subcortical RS grad2 diagnostic_groupcontrol -0.0282857 0.0087827 -3.2206173 0.0014038 0.0091245
Ventral-Multimodal RS grad2 diagnostic_groupcontrol 0.0073589 0.0182964 0.4022066 0.6877870 0.7774983
Visual1 RS grad2 diagnostic_groupcontrol 0.0179466 0.0256228 0.7004131 0.4841526 0.6511018
Visual2 RS grad2 diagnostic_groupcontrol 0.1144097 0.0157738 7.2531338 0.0000000 0.0000000
Auditory EA grad3 diagnostic_groupcontrol -0.0156858 0.0110482 -1.4197603 0.1566019 0.3393040
Cingulo-Opercular EA grad3 diagnostic_groupcontrol 0.0044706 0.0049661 0.9002179 0.3686472 0.5868261
Default EA grad3 diagnostic_groupcontrol 0.0034915 0.0054026 0.6462660 0.5185470 0.6630601
Dorsal-Attention EA grad3 diagnostic_groupcontrol 0.0017452 0.0067718 0.2577188 0.7967813 0.8513553
Frontoparietal EA grad3 diagnostic_groupcontrol 0.0031561 0.0061960 0.5093809 0.6108187 0.7218766
Language EA grad3 diagnostic_groupcontrol 0.0031840 0.0088005 0.3618029 0.7177260 0.7997519
Orbito-Affective EA grad3 diagnostic_groupcontrol -0.0057439 0.0088543 -0.6487161 0.5169637 0.6630601
Posterior-Multimodal EA grad3 diagnostic_groupcontrol 0.0299112 0.0114921 2.6027559 0.0096563 0.0376597
Somatomotor EA grad3 diagnostic_groupcontrol -0.0209442 0.0063079 -3.3203199 0.0009976 0.0077814
Subcortical EA grad3 diagnostic_groupcontrol 0.0226621 0.0062437 3.6296057 0.0003279 0.0036180
Ventral-Multimodal EA grad3 diagnostic_groupcontrol -0.0112839 0.0106985 -1.0547187 0.2923096 0.5066699
Visual1 EA grad3 diagnostic_groupcontrol -0.0142646 0.0085054 -1.6771183 0.0944466 0.2166716
Visual2 EA grad3 diagnostic_groupcontrol -0.0053467 0.0038924 -1.3736174 0.1704736 0.3500366
Auditory RS grad3 diagnostic_groupcontrol 0.0121786 0.0156414 0.7786139 0.4367536 0.6193960
Cingulo-Opercular RS grad3 diagnostic_groupcontrol 0.0067627 0.0080353 0.8416301 0.4005919 0.6116157
Default RS grad3 diagnostic_groupcontrol 0.0235588 0.0071710 3.2852716 0.0011260 0.0079840
Dorsal-Attention RS grad3 diagnostic_groupcontrol -0.0253400 0.0110227 -2.2989032 0.0221218 0.0750218
Frontoparietal RS grad3 diagnostic_groupcontrol 0.0051760 0.0085082 0.6083469 0.5433672 0.6730968
Language RS grad3 diagnostic_groupcontrol -0.0239176 0.0120263 -1.9887681 0.0475352 0.1373238
Orbito-Affective RS grad3 diagnostic_groupcontrol 0.0402752 0.0152691 2.6376983 0.0087341 0.0358556
Posterior-Multimodal RS grad3 diagnostic_groupcontrol -0.0206704 0.0182793 -1.1308072 0.2589404 0.4697058
Somatomotor RS grad3 diagnostic_groupcontrol -0.0180773 0.0103476 -1.7469985 0.0815486 0.1987746
Subcortical RS grad3 diagnostic_groupcontrol 0.0410243 0.0101849 4.0279734 0.0000696 0.0013565
Ventral-Multimodal RS grad3 diagnostic_groupcontrol -0.0345523 0.0179343 -1.9266061 0.0548694 0.1475797
Visual1 RS grad3 diagnostic_groupcontrol -0.0571140 0.0167060 -3.4187666 0.0007062 0.0061204
Visual2 RS grad3 diagnostic_groupcontrol -0.0299806 0.0083366 -3.5962783 0.0003711 0.0036180
all_roi_results <- spins_grads %>%
  inner_join(lol_spins_behav, by = c("Subject" = "subject")) %>%
  mutate( fd_mean = if_else(Task=="EA", fd_mean_emp, `fd_mean.rest_bold`)) %>%
  pivot_longer(grad1:grad4, names_to = "grad_num", values_to = "grad_value") %>%
    ungroup() %>%
  group_by(Network, Task, grad_num, ROI) %>%
  do(tidy(lm(grad_value ~ diagnostic_group + demo_age_study_entry + demo_sex + fd_mean + scanner, data = .))) %>%
  ungroup() %>%
  group_by(term) %>%
  mutate(p_FDR = p.adjust(p.value, method = "fdr"))
  
all_roi_results %>% write_csv('ROIwise_SPINS_SSDvsHC_result_wGSR.csv')
all_roi_results %>%
  filter(term == "diagnostic_groupcontrol", p_FDR < 0.05)
all_roi_results %>%
  filter(term == "diagnostic_groupcontrol", p_FDR < 0.05) %>%
  count(Task, grad_num) %>%
  arrange(Task, grad_num)
all_roi_results %>%
  filter(term == "diagnostic_groupcontrol", p_FDR < 0.05) %>%
  count(Task, grad_num, Network) %>%
  pivot_wider(names_from = grad_num, values_from = n)